package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.AgedmallOrderLogisticsMapper;
import org.linlinjava.litemall.db.dao.order_manage.BackendOrderLogisticsMapper;
import org.linlinjava.litemall.db.domain.AgedmallOrderLogistics;
import org.linlinjava.litemall.db.domain.AgedmallOrderLogisticsExample;
import org.linlinjava.litemall.db.vo.app.ExpressInfoVo;
import org.linlinjava.litemall.db.vo.app.ExpressVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class AgedmallOrderLogisticsService {
    @Resource
    private AgedmallOrderLogisticsMapper agedmallOrderLogisticsMapper;
    @Resource
    private BackendOrderLogisticsMapper backendOrderLogisticsMapper;

    public void addOrderLogistics(Integer orderId, Integer type, String expressId, String expressName, String title, String desc) {
        AgedmallOrderLogistics logistics = new AgedmallOrderLogistics();
        logistics.setOrderId(orderId);
        logistics.setType(type);
        logistics.setExpressId(expressId);
        logistics.setExpressName(expressName);
        logistics.setTitle(title);
        logistics.setDesc(desc);
        logistics.setDeleted(false);
        logistics.setAddTime(LocalDateTime.now());
        agedmallOrderLogisticsMapper.insertSelective(logistics);
    }

    public List<ExpressVo> logisticsInfoList(Integer type, Integer subOrderId) {
        List<ExpressVo> expressVoList = backendOrderLogisticsMapper.getExpressVoList(type, subOrderId);
        for (ExpressVo expressVo : expressVoList) {
            List<ExpressInfoVo> expressInfoVoList = backendOrderLogisticsMapper.getExpressInfoVoList(type, subOrderId, expressVo.getExpressId());
            expressVo.setExpressInfoList(expressInfoVoList);
        }
        return expressVoList;
    }
}
